



  <?php form_head("admin/material_add$type_id/$material_id/$order_item_id","เพิ่มครุภัณใหม่") ?>
  <?php if($order_item_id){ ?>
    <input type="hidden" name="ref_order_item_id" value="<?php $order_item_id; ?>" />
    <?php } ?>
         <?php text_field("name","ชื่อ",$value,0); ?>
		 <?php text_field("brand","ยี้ห้อ",$value,1); ?>
		 <?php text_field("buy_date","วันที่ซื้อ",$value,0,"date"); ?>
		<?php text_field("model","รุ่น",$value,0); ?>
		<?php text_field("buy_price","ราคาซื้อ",$value,1); ?>
		<?php text_field("warranty","การรับประกัน",$value,1,"width800"); ?>
<?php 

		 $rows =  $this->db->query("select budget_id, concat(budget_name,'-', year) as budget_name from budgets")->result_array();

		 select_field("budget_id","ชนิดงบประมาณ",$rows,"budget_name",$value,"โปรดเลือก",0,null,"",2); 

		//select_field($name,$label,$rows,$label_value,$row,$cleaner = 0,$first_label="โปรดเลือก",$class ="",$type=1)

		 ?>

	

		      	<?php 
		      $sql = "SELECT  CONCAT( meterial_base_categories.cat_base_name,'|',material_categories.category_name) as category_name,
		      material_categories.category_id, 
		      	meterial_base_categories.sort_order
		      FROM meterial_base_categories INNER JOIN material_categories ON meterial_base_categories.cat_base_id = material_categories.cat_base_id order by sort_order asc";

		 $rows =  $this->db->query($sql)->result_array();

		 select_field("category_id","หมวด",$rows,"category_name",$value,"โปรดเลือก",1,null,"",2); 

		 ?>

		

		      	<?php 

		 $rows =  $this->db->query("select company_id,concat(company_name,'')as company_name from company")->result_array();

		 select_field("company_id","บริษัทจัดหา",$rows,"company_name",$value,"โปรดเลือก",0,null,"",2); 
		//select_field($name, $label, $rows, $label_value, $row)
		 ?>

		  <?php //text_field("responsible","เจ้าหน้าที่รับผิดชอบ",null,1); ?>

		 

		<?php area_field("detail","รายละเอียด",$value,1,"width800 height100"); 
		
		?>

        <?php image_field("thumbnail","รูป",null,1); ?> 
        
        โดยมีรายการ ครุภัณทั้งหมดดังนี้
        
       <?php //print_r($type_id); ?>
<table class="list list-form items">
          <tbody><tr class=	" odd">
            <th style="width:20px;"></th>
            <th style="width: 100px;">เลขที่ครุภัณฑ์/วัสดุ</th>
             <th style="width: 100px;">Serial Code(ถ้ามี)</th>
            
             <th style="width: 400px;">รายละเอียด</th>
              
            <th></th>
        
          </tr>
                 
                 <?php 
                 $i= 1;
                 for($i=1;$i<=  $value["amount"];$i++){ ?>
                  
          <tr class="item-<?php echo $i;  ?>" >
            
            
            <td><?php echo $i; ?></td>
            <td><input <?php if($type_id==1){ echo 'readonly="readonly"'; } ?> name="code[]" class="code" value="<?php if($type_id==1){ echo "RUN_AUTO"; }else{ if(isset($_POST["code"])){ echo $_POST["code"][($i-1)]; }} ?>" type="text" /></td>
             <td><input name="serial_code[]" class="serial_code" value="<?php if(isset($_POST["serial_code"])){ echo $_POST["serial_code"][($i-1)]; } ?>" type="text" /></td>
           	  
           	  <td><input name="remark[]" class="remark" value="<?php if(isset($_POST["remark"])){ echo $_POST["remark"][($i-1)]; } ?>" type="text" /></td>
           	
           
            
          </tr>
               <?php } ?>    
        
                  </tbody></table>
                 
                <a onclick="item_new();" href="javascript:void(0);"> เพิ่มรายการใหม่</a>

 <div class="cleaner"></div>
 
<input type="hidden" name="item_count" value="<?php echo ($i-1); ?>" >

<?php form_footer(); ?>
 <script type="text/javascript">
 var item_count = <?php echo $i; ?>;
                 
 function item_new()
 {
    var html = '<tr class="item-'+item_count+'" ><td>'+item_count+'</td><td><input <?php if($type_id==1){ echo 'readonly="readonly"'; } ?> type="text" value="<?php if($type_id==1){ echo 'RUN_AUTO'; } ?>" class="code" name="code[]"></td><td><input type="text" value="" class="code" name="serial_code[]"></td> <td><input type="text" value="" class="remark" name="remark[]"></td></tr>';
 	$("input[name=item_count]").val((item_count));
    item_count++;
 	$("table.items").append(html);
 }

function check_code(code)
{
	

}
 function item_delete(id)
 {
	

		$.ajax({
			  type: "POST",
			  url: "<?php echo  site_url("service/materail_item_delete"); ?>/",
			  data: "code="+id,
			  success: function(html){
				 window.location.reload();
			  }
			});
 }
 
 </script> 

	

          

         

    

      